var setting = {
	showLine: true,
	async: {
		enable: true,
		type:'post',
		dataType:'json',
		url:contextPath+"/admin/menumanager/toQueryZtreeMenu.action",
		autoParam:["id=menuForm.id"],
		otherParam:["menuForm.root",true,"r_math",Math.random()],
		dataFilter: filter
	},
	data: {
		simpleData: {
			enable: true,
			idKey: "id",
			pIdKey: "pId",
			rootPId: 0,
		}
	},
	view: {
		addHoverDom: addHoverDom,
		removeHoverDom: removeHoverDom,
		selectedMulti: false
	},
	edit: {
	    drag: {
			autoExpandTrigger: true,
			//prev: dropPrev,
			//next: dropNext
			inner:dropInner
		},
		enable: true,
		editNameSelectAll: false,
		showRemoveBtn: true,
		showRenameBtn: true
	},
	callback: {
		beforeDrag: beforeDrag,
		beforeDblClick:null,
		beforeRemove:beforeRemoveFun,
		beforeEditName:beforeEditNameFun,
		
		onDblClick:null,
		onRemove:onRemoveFun,
		onRename:onRenameFun,
		onDrop: zTreeOnDrop
	}
}
function zTreeOnDrop(event, treeId, treeNodes, targetNode, moveType) {
	if(moveType=="inner"){
		if(treeNodes.length==1){
			eval("onDrop"+treeId+"Fun("+treeNodes[0].id+",'"+treeNodes[0].name+"',"+targetNode.id+",'"+targetNode.tId+"','"+targetNode.name+"',"+treeNodes[0].isParent+","+targetNode.isMenuType+")");
		}
	}
};
function beforeRemoveFun(treeId, treeNode){
	return eval("beforeRemove"+treeId+"Fun("+treeNode.id+","+treeNode.pId+")");
}
function onRemoveFun(event, treeId, treeNode){
	eval("remove"+treeId+"Fun("+treeNode.id+","+treeNode.pId+")");
}
function beforeEditNameFun(treeId, treeNode, newName, isCancel){
	eval("beforeModify"+treeId+"Fun("+treeNode.id+","+treeNode.pId+")");
}
function onRenameFun(event, treeId, treeNode, isCancel){
	eval("modify"+treeId+"Fun("+treeNode.id+","+treeNode.pId+")");
}
function beforeDrag(treeId, treeNodes) {
	for (var i=0,l=treeNodes.length; i<l; i++) {
		if (treeNodes[i].drag === false) {
			return false;
		} else if (treeNodes[i].parentTId && treeNodes[i].getParentNode().childDrag === false) {
			return false;
		}
	}
	return true;
}

function addHoverDom(treeId, treeNode) {
	var sObj = $("#" + treeNode.tId + "_span");
	if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
	var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
		+ "' title='add node' onfocus='this.blur();'></span>";
	sObj.after(addStr);
	var btn = $("#addBtn_"+treeNode.tId);
	if (btn) btn.bind("click", function(){eval("add"+treeNode.tId.split("_")[0]+"Fun("+treeNode.id+","+treeNode.pId+",'"+treeNode.tId+"')")});
	treeNode.isHideAdd&&$("#addBtn_"+treeNode.tId).hide();
	treeNode.isHideEdit&&$("#"+treeNode.tId+"_edit").hide();
	treeNode.isHideRemove&&$("#"+treeNode.tId+"_remove").hide();
}
function filter(treeId, parentNode, childNodes) {
	if (!childNodes.jumpType) return null;
	childNodes = childNodes.json;
	for (var i=0, l=childNodes.length; i<l; i++) {
		childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
		childNodes[i].isMenuType&&(childNodes[i].icon = contextPath+"/res/js/jquery/ztree/zTreeStyle/img/diy/5.png");
	}
	return childNodes;
}
function removeHoverDom(treeId, treeNode) {
	$("#addBtn_"+treeNode.tId).unbind().remove();
}
function dropPrev(treeId, nodes, targetNode) {
	var pNode = targetNode.getParentNode();
	if (pNode && pNode.dropInner === false) {
		return false;
	} else {
		for (var i=0,l=curDragNodes.length; i<l; i++) {
			var curPNode = curDragNodes[i].getParentNode();
			if (curPNode && curPNode !== targetNode.getParentNode() && curPNode.childOuter === false) {
				return false;
			}
		}
	}
	return true;
}
function dropNext(treeId, nodes, targetNode) {
	var pNode = targetNode.getParentNode();
	if (pNode && pNode.dropInner === false) {
		return false;
	} else {
		for (var i=0,l=curDragNodes.length; i<l; i++) {
			var curPNode = curDragNodes[i].getParentNode();
			if (curPNode && curPNode !== targetNode.getParentNode() && curPNode.childOuter === false) {
				return false;
			}
		}
	}
	return true;
}
function dropInner(treeId, nodes, targetNode) {
	if (targetNode && targetNode.dropInner === false) {
		return false;
	}
	return true;
}
